<template>
  <div class="root1">
    <div class="title">WEB元素工坊</div>
    <div class="name">欢迎您, {{ myname }}</div>
    <div class="logintip" v-show="showlogintip">
      <el-link style="color: black" @click="gologin"
        >点我登录使用更多功能</el-link
      >
    </div>
    <div class="items">
      <div class="item" @click="jump(0)"><strong>Btn</strong>按钮</div>
      <div class="item" @click="jump(1)">
        <caret-right style="width: 20px; height: 20px" />输入
      </div>
      <div class="item" @click="jump(2)">
        <expand style="width: 20px; height: 20px" />段落
      </div>
    </div>
    <div class="items1"></div>
    <div class="items2">
      <div class="item" @click="viewstore">
        <star-filled style="width: 20px; height: 20px" />收藏
      </div>
      <div class="item"><list style="width: 20px; height: 20px" />指南</div>
    </div>
  </div>
</template>

<script>
import { ElNotification } from "element-plus";
export default {
  data() {
    return {
      paths: ["/mybutton", "/myinput", "/mytext"],
      myname: "",
      showlogintip: false,
    };
  },
  created() {
    this.myname = window.localStorage.getItem("curname");
    if (this.myname == "未登录用户") {
      this.showlogintip = true;
    }
  },
  methods: {
    jump(i) {
      this.$router.push({ path: this.paths[i] });
    },
    viewstore() {
      let name = window.localStorage.getItem("curname");
      //如果在没有token的情况下想进入收藏，将提示先登录
      if (
        window.localStorage.getItem(name) == null
      ) {
        ElNotification({
          title: "当前登录已过期",
          message: "请重新登录以查看收藏",
          type: "warning",
          duration: 2000,
          position: "bottom-left"
        });
      } else if(window.localStorage.getItem(name) == "unlogin"){
        ElNotification({
          title: "您还未登录",
          message: "请登录以查看收藏",
          type: "warning",
          duration: 2000,
          position: "bottom-left"
        });
      } else {
        this.$router.push({ path: "/clt" });
      }
    },
    gologin() {
      this.$router.push({ path: "/login" });
    },
  },
};
</script>

<style scoped>
.items {
  display: flex;
}
.items > * {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background-color: rgba(108, 80, 137, 0.3);
  background: rgba(108, 80, 137, 0.3);
  border-radius: 40px;
  width: 50px;
  height: 50px;
  box-shadow: 3px 3px 11px #512b57;
  padding: 10px;
  margin: 10px;
  text-align: center;
}
.items2 > * {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background-color: rgba(108, 80, 137, 0.3);
  background: rgba(108, 80, 137, 0.3);
  border-radius: 40px;
  width: 50px;
  height: 50px;
  box-shadow: 3px 3px 11px #512b57;
  padding: 10px;
  margin: 10px;
  text-align: center;
}
.items2 {
  display: flex;
}
.item:hover {
  color: #eae5f0;
  font-weight: bold;
  cursor: pointer;
}

.root1 {
  width: 100%;
}
.title {
  font-size: 30px;
  font-weight: bold;
  margin: 30px 18px;
}
.name {
  font-size: 20px;
  margin: 0px 18px 3px;
  color: #eae5f0;
}
.logintip {
  font-size: 14px;
  color: #eae5f0;
  margin: 0px 18px 30px;
}
</style>